<?php
/**
 * Generate shipping labels for orders
 * @author Andy Rich <andy.rich@gmail.com>
 * @version 1.0
 * @since 2013-11-13
 */
require_once "database.php";
require_once 'order.php';
require_once 'customer.php';

loginInfo::update_login ();

?>

<html>
	<head>
		<title>Opol - Label View</title>
	</head>
	<body>


<?php if (!$_GET) : 
	# Don't apply style or menu to the actual label page
	require "menu.php";
	?>
	<link rel="stylesheet" type="text/css" href="opol.css">
	<form name="text" action="view_label.php" method="get" target="_blank">
	<label>Order Number: </label>
		<input name="order" type="text" size="10"> <br>
		<label>&nbsp;</label>
		<input type="submit" value="Search"> <br>
	</form>
<?php
else :
	# Get "From" address
	$config = parse_ini_file("config.ini");
	$from = $config["from_address"];

	# Get "To" address
	$db = new database ();
	$id = $_GET["order"];
	$order = new order ($id);
	$order->init ($db);

	$customer = new customer ($order->customer);
	$customer->init($db);

	$ship_addr 	= $order->shipping_addr;
	$hold 		= $order->hold;
	$pri 		= $order->priority;
	$cost 		= $order->price;
	$instr 		= $order->special_instructions;
	$due 		= $order->deadline;

	$cust_name 	= $customer->name;
	$cust_email = $customer->email;
	$cust_phone = $customer->phone_num;
	$cust_addr 	= $customer->address;

	$to = "$cust_name\n$ship_addr";
  
	# Sanitize
	$to 	= nl2br(htmlentities($to));
	$from 	= nl2br(htmlentities($from));

	# Print the label
	print $from;
	print "<br><br><br>";
	print "<center>$to</center>";
	print "<br><br>";
	print "<b> Re: Order #$id</b>";
endif; ?>

	</body>
</html>